/****************************************************************************
 * @file    : lin_define.h
 * @author  : Nonosns MCU Team
 * @version : V2.0
 * @Date    : 2023/4/7
 * @brief   : lin stack file 
 * @note
 * Copyright (C) 2023 Novosense All rights reserved.
 ****************************************************************************/
#ifndef __LIN_DEFINE_H
#define __LIN_DEFINE_H

//======================================================================
// Compiler switches for test and debug purposes
//======================================================================


#if 0    // ##### defined in project options for target 'Debug'
  #define DEBUG                   // if defined, some debug options can be enabled during implementation/evaluation
                                  // must be disabled for final software release
#endif

#ifdef DEBUG
  //#define  DEBUG_PORT_TOGGLE       // if defined, some ports are configured to output test signals
  #define DEBUG_ERROR_COUNTER      // if defined, three error counters are sent in g_nodeConfigFrameTable[RESPONSE_ERROR_FRAME] byte 4..6
  #define DEBUG_TRACE_ENABLE
#endif

//======================================================================
// Compiler switches for different options
//======================================================================

#define USE_LGPIO_0_1_2        
#if (defined USE_LGPIO_0_1_2) && (defined DEBUG_PORT_TOGGLE)
  #error "### USE_LGPIO_0_1_2 and DEBUG_PORT_TOGGLE cannot be defined simultaneously !!!"
#endif

#define  L_NAD_EEPROM    // if defined, NAD is read from EEPROM (if there is a valid NAD stored)
#define  L_PID_EEPROM    // if defined, PID table is read from EEPROM (if there is a valid PID table stored)

#define L_UDS_BOOTLOADER_UPDATE // if user want to use uds bootloader update firmware , please define micro
//======================================================================
// global definitions
//======================================================================
#define SW_VERSION      0x20

#define TRUE            1
#define FALSE          !TRUE

#ifndef NULL
  #define NULL         ((void *)0)    // the NULL pointer
#endif

// UART and LIN setup
// ------------------
#define LIN_LOM             0         // 0: LIN port switched off by HW for VBVDD < VBVDDU
                                      // 1: LIN port not switched off by HW for VBVDD < VBVDDU
  
#define SLEW_10_KBPS        3                        // slew rate for 10kbps=1V/us
#define SLEW_20_KBPS        2                        // slew rate for 20kbps=2V/us
//#define SLEW_INFINITE    1                        // slew rate=infinite
#define SLEW_INFINITE        0                        // slew rate=infinite

// definition of LINUART interrupt flags
#define  LINUART_TXC      BIT_0
#define  LINUART_RXC      BIT_1
#define  LINUART_TXB      BIT_2
#define  LINUART_RXOV     BIT_3
#define  LINUART_PE       BIT_4
#define  LINUART_BRROK    BIT_5
#define  LINUART_TXEND    BIT_6
#define  LINUART_FE       BIT_7
#define  LINUART_TO       BIT_8
#define  LINUART_TXFO     BIT_9
#define  LINUART_TXFF     BIT_10
#define  LINUART_RXFF     BIT_11
#define  LINUART_TXFE     BIT_12
#define  LINUART_RXFE     BIT_13
#define  LINUART_BRK      BIT_14
#define  LINUART_TXFL     BIT_15
#define  LINUART_RXFL     BIT_16
#define  LINUART_TXFC     BIT_17
#define  LINUART_TXERR    BIT_18


// definition of LIN interrupt flags
#define  LIN_LINFE    BIT_0
#define  LIN_LINRE    BIT_1
#define  LIN_OC       BIT_2
#define  LIN_DOMTO    BIT_3
#define  LIN_BEND     BIT_4


/* following code generated by LIN Tool From LDF */

#define LIN_BITRATE      19200    // supported values: 1000, 2400， 4800， 9600， 10400, 19200

// UART clock = 32MHz
// Note: UART_BITLEN is used for definition of the length for the baud Rate
#if LIN_BITRATE == 1000
    #define UART_BRR            (32000)
    #define LIN_SLEW            SLEW_10_KBPS
#elif LIN_BITRATE == 2400
    #define UART_BRR            (13334 - 1)
    #define LIN_SLEW            SLEW_10_KBPS
#elif LIN_BITRATE == 4800
    #define UART_BRR            (6667 - 1)
    #define LIN_SLEW            SLEW_10_KBPS
#elif LIN_BITRATE == 9600
    #define UART_BRR            (3334 - 1)
    #define LIN_SLEW            SLEW_10_KBPS
#elif LIN_BITRATE == 10400
    #define UART_BRR            (3077 - 1)
    #define LIN_SLEW            SLEW_10_KBPS
#elif LIN_BITRATE == 19200
    #define UART_BRR            (1667 - 1)
    #define LIN_SLEW            SLEW_20_KBPS
#elif LIN_BITRATE == 20000
    #define UART_BRR            (1600)
    #define LIN_SLEW            SLEW_20_KBPS
#endif


#define  L_LIN_2_2                // if defined, LIN V2.2 is supported (otherwise, LIN V2.0 is supported)
                                  // The following LIN 2.2 features are implemented:
                                  //  - configuration frame "AssignFrameIdRange"
                                  //  - obsolete function "Assign Frame Identifier" deleted
                                  //  - message IDs deleted
                                  //  - support for message IDs within "Read by Identifiers" deleted

#define   L_CONFIG_IDENTIFIER     // configuration option enabled
                                  // Since node configuration is mandatory in LIN 2.0, this switch can
                                  // be disabled only for debug purposes.

#ifdef   L_CONFIG_IDENTIFIER      // configuration option enabled
    #define   L_SNPD_BSM          // if defined, LIN SNPD (via Bus Shunt Method 1) is enabled
#endif


#endif          /* __LIN_DEFINE_H */
